package day9;

import java.util.Arrays;
import java.util.Comparator;

//lamdba表达式  实现Arrays.sort排序 手写排序规则
public class demo {
    public static void main(String[] args) {
        Integer[] nums = {7,3,1,5,2,6,4};
        System.out.println(Arrays.toString(nums));
        //默认升序  如果想换排序规则  需要比较器对象
        //比较器对象:comparator  外部比较器
        //java泛型不可以写基本类型
        //Comparator<Integer> c = (Integer o1,Integer o2) -> {return o2-o1;};

        Arrays.sort(nums,(o1,o2) -> o1-o2);
        System.out.println(Arrays.toString(nums));
    }
}

class Student{
    int id;
    String name;
    double score;
    //java中一般情况下  提供了有参构造和无参构造
    public Student(int id, String name, double score) {
        this.id = id;
        this.name = name;
        this.score = score;
    }
    //java打印引用类型 默认打印引用地址()
    //重写toString 父类打印地址的tostring就失效了
    public String toSting() {
        return id + " " + name + " " + score;
    }

    public Student(){
        Student s = new Student();
        Student[] stus={
                new Student(10,"444",44),
                new Student(1,"111",11),
                new Student(2,"222",22),
                new Student(3,"333",33),
                new Student(4,"444",44),
                new Student(5,"555",55),
                new Student(6,"666",66),
                new Student(7,"777",77),
        };
        System.out.println(Arrays.toString(stus));
        //默认工具类方法无法对对象进行排序，因为
        Arrays.sort(stus,((o1, o2) -> {
            int retsult = (int)(o2.score-o1.score);
            if(retsult == 0){
                retsult=o1.id-o2.id;
            }
            return retsult;
        }));
        System.out.println(Arrays.toString(stus));
    }
}